package com.api.syh56.shengyunhui.controller.admin;

import com.api.syh56.shengyunhui.common.CommonResult;
import com.api.syh56.shengyunhui.entity.adminEntity.AdminVersion;
import com.api.syh56.shengyunhui.service.AdminVersionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 版本管理
 */
@RestController
@RequestMapping("admin/version")
public class AdminVersionController {
    @Autowired
    private AdminVersionService adminVersionService;

    /**
     * 添加版本
     * @param adminVersion
     * @return
     */
    @PostMapping("insertVersion")
    public CommonResult<Object> insert(@RequestBody AdminVersion adminVersion){
        adminVersionService.save(adminVersion);
        return CommonResult.success(null);
    }

    /**
     * 修改版本信息
     * @param adminVersion
     * @return
     */
    @PostMapping("updateVersion")
    public CommonResult<Object> updateById(@RequestBody AdminVersion adminVersion){
        adminVersionService.updateById(adminVersion);
        return CommonResult.success(null);
    }

    /**
     * 查看版本信息
     * @return
     */
    @GetMapping("getVersion")
    public CommonResult<Object> getVersion(){
        QueryWrapper<AdminVersion> wrapper = new QueryWrapper<>();
        List<AdminVersion> adminVersions = adminVersionService.list(wrapper);
        AdminVersion adminVersion = adminVersions.get(0);
        return CommonResult.success(adminVersion);
    }
}
